package com.xixi.FragTab;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

import com.xixi.FragTab.R;

public class Fragment2 extends Fragment{
	
	int[] deviceId = { R.string.device1,R.string.device2, R.string.device3,
			R.string.device4, R.string.device5, R.string.device6, R.string.device7 };
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		
		View v=inflater.inflate(R.layout.fragment_2, null);	
		
		ListView ls = (ListView)v. findViewById(R.id.DevicesList);
		
		BaseAdapter ba = new BaseAdapter() {

			@Override
			public View getView(int arg0, View arg1, ViewGroup arg2) {
				// TODO Auto-generated method stub

				LinearLayout ll = new LinearLayout(getActivity());
				ll.setOrientation(LinearLayout.VERTICAL);
				ll.setPadding(5, 5, 5, 5);
				TextView tv = new TextView(getActivity());
				tv.setText(getResources().getText(deviceId[arg0]));
				tv.setTextSize(20);
				tv.setPadding(5, 5, 5, 5);
				tv.setGravity(Gravity.CENTER);
				ll.addView(tv);
				return ll;
			}

			@Override
			public long getItemId(int arg0) {
				// TODO Auto-generated method stub
				return 0;
			}

			@Override
			public Object getItem(int arg0) {
				// TODO Auto-generated method stub
				return null;
			}

			@Override
			public int getCount() {
				// TODO Auto-generated method stub
				return 7;
			}
		};
		
		ls.setAdapter(ba);
		ls.setPadding(5, 5, 5, 100);
		
		ls.setOnItemClickListener(new OnItemClickListener() {
			
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				// TODO Auto-generated method stub
				Intent intent=new Intent();
				intent.setClass(getActivity(), DeviceDetails.class);
				startActivity(intent);
			}
		});
			
		return v;	
	}	
}